package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanOrder;
import nero.yncc.com.createart.bean.BeanShopCar;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.utils.ImageUtils;
import nero.yncc.com.createart.utils.ToastUtil;

/**
 * Created by nero on 17-6-30.
 */

public class AdapterMyOrder extends BaseAdapter {


    Context context;
    ArrayList<BeanOrder> arrayList;

    public AdapterMyOrder(Context context, ArrayList<BeanOrder> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if(view==null){
             view = LayoutInflater.from(context).inflate(R.layout.adapter_my_order, viewGroup, false);
             holder = new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder) view.getTag();
        }

        BeanOrder beanOrder=arrayList.get(i);
        ArrayList<BeanShopCar> arrayList_shopcar=beanOrder.getGoods_list();
        holder.tv_num.setText("订单编号："+beanOrder.getOrder_id());
        holder.tv_state.setText(beanOrder.getOrder_status_desc());
        BeanShopCar.goods goods_first=arrayList_shopcar.get(0).getList().get(0);
        ImageUtils.BindImage(context,holder.iv_image,goods_first.getOriginal_img(),1);
        holder.tv_title.setText(goods_first.getGoods_name());
        holder.tv_state2.setText(beanOrder.getOrder_status_desc());
        holder.tv_allnum.setText("共"+arrayList_shopcar.size()+"件商品");
        holder.tv_money.setText(beanOrder.getTotal_amount());
        if(beanOrder.getOrder_status_code().equals("WAITPAY")){
            //待支付
            holder.tv_pay.setVisibility(View.VISIBLE);
            holder.tv_pay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ToastUtil.showToast(context,"暂未开放");
                }
            });
        }
        return view;
    }

    class Holder{
        TextView tv_num,tv_state,tv_title,tv_state2,tv_allnum,tv_money,tv_pay;
        ImageView iv_image;
        public Holder(View itemView) {
            tv_num=itemView.findViewById(R.id.tv_num);
            tv_state=itemView.findViewById(R.id.tv_state);
            iv_image=itemView.findViewById(R.id.iv_image);

            tv_title=itemView.findViewById(R.id.tv_title);
            tv_state2=itemView.findViewById(R.id.tv_state2);
            tv_allnum=itemView.findViewById(R.id.tv_allnum);
            tv_money=itemView.findViewById(R.id.tv_money);
            tv_pay=itemView.findViewById(R.id.tv_pay);
            iv_image=itemView.findViewById(R.id.iv_image);
            iv_image=itemView.findViewById(R.id.iv_image);
            iv_image=itemView.findViewById(R.id.iv_image);
        }
    }
}
